<?php
include("../../product/model.php");
include("../../type/model.php");
include("../view/basefunction.php");

// 从数据库里查询出这个产品的信息
$product = model_get_product_details($_GET["id"]);
$type_list = get_type_list('product');
$body_html = represent_edit_form($product, $type_list);

include_once("../template/layout.php");

// ---------------------------------
// view
// ---------------------------------
function represent_edit_form($product, $type_list)
{
	$htmlData = '';
	if (!empty($product['details']))
	{
		if (get_magic_quotes_gpc())
		{
			$htmlData = stripslashes($product['details']);
		} else
		{
			$htmlData = $product['details'];
		}
	}

	$form_html =
"<script charset='utf-8' src='../editor/kindeditor.js'></script>
<script>
	KE.show({
		id : 'details',
		cssPath : './index.css',
		afterCreate : function(id) {
			KE.event.ctrl(document, 13, function() {
				KE.sync(id);
				document.forms['example'].submit();
			});
			KE.event.ctrl(KE.g[id].iframeDoc, 13, function() {
				KE.sync(id);
				document.forms['example'].submit();
			});
		}
	});
</script>
<form action='./edit_post.php' method='post' enctype='multipart/form-data'>
<input type='hidden' name='id' value='" . $product["id"] . "'/>
<input type='hidden' name='old_image' value='" . $product["big_image"] . "'/>
<input type='hidden' name='MAX_FILE_SIZE' value='1000000' />
产品名称：<input type='text' name='name' value='" . $product["name"] . "' /><br />
产品图片：<img src='../../upload/" . $product["big_image"] . "' style='width:300px'>
新图片：<input type='file' name='image' /><br />
所属分类：" . represent_type_list($type_list, $product["type_id"], "product") . " <br />
型号：<input type='text' name='model' value='" . $product["model"] . "'/><br />
规格：<input type='text' name='specification' value='" . $product["specification"] . "' /><br />
市场价格：<input type='text' name='market_price' value='" . $product["market_price"] . "' /><br />
促销价：<input type='text' name='promotional_price' value='" . $product["promotional_price"] . "'/><br />
简介：<input type='text' name='intro' value='" . $product["intro"] . "'/><br />
详细介绍：<br />
<textarea id='details' name='details' style='width:700px;height:300px;visibility:hidden;'>"
. htmlspecialchars($htmlData) .
"
</textarea>
<input type='submit' value='更新' />
</form>";

	return $form_html;
}

?>
